/*
 * Created on 20 ao�t 2005
 *
 */

package picoevo.gp.evolution;

import picoevo.core.evolution.VariationOperator;
import picoevo.core.representation.EvolutionObject;
import picoevo.gp.representation.Element_Node_TreeGP_Root;
import picoevo.toolbox.Dictionary;

/**
 * this variation operator may be attached (exclusively) to a root node element
 * operator is **automaticaly** applied (P=1)
 */

public class VariationOperator_Element_TreeGP_ForcedReInitialize extends VariationOperator {

	VariationOperator_Element_TreeGP_ForcedReInitialize(String __name) {
		super(__name);
	}

	VariationOperator_Element_TreeGP_ForcedReInitialize(String __name, double __operatorRate) {
		super(__name, __operatorRate);
	}

	@Override
	public void applyOperator(EvolutionObject __element) {
		Element_Node_TreeGP_Root element = (Element_Node_TreeGP_Root) __element;
		element.resetSuccessorConnections(); // successors should be garbage
		// collected.
		if (element.getTemplate().getIntProperty("MaxInitDepth") <= 1)
			element.performInitialisation();
		else
			element.performInitialisation(element.getTemplate().getIntProperty("MaxInitDepth"), Dictionary.growMethod, true);
	}
}
